package bookpos.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import bookpos.dao.OrderItemDao;
import bookpos.entity.OrderItem;
import bookpos.service.OrderItemService;
/**
 * 订单项目业务实现类
 * @author WZB
 *
 */
@Service
public class OrderItemServiceImpl implements OrderItemService {
	@Autowired
	private OrderItemDao dao;

	public void save(OrderItem vo) {
		dao.save(vo);
		
	}
	public void update(OrderItem vo) {
		dao.update(vo);
		
	}
	public void delete(int id) {
		OrderItem vo = dao.get(id);
		dao.delete(vo);
	}

	public List<OrderItem> findAll(int page, int rows, String sort, String order) {
		return dao.findAll(page, rows, sort, order);
	}

	public int getTotal() {
		return dao.countAll();
	}
	
	public void saveItems(String[] ids, String[] qs, String[] prices,String[] totals,String oid) {
		if(ids.length == qs.length){
			int leng = ids.length;
			System.out.println(leng);
			for(int i=0;i<leng;i++){
				System.out.println("oi");
				OrderItem oi = new OrderItem();
				oi.setBid(Integer.parseInt(ids[i]));
				oi.setQuantity(Integer.parseInt(qs[i]));
				oi.setPrice(Double.parseDouble(prices[i]));
				oi.setTotal(Double.parseDouble(totals[i]));
				oi.setOid(oid);
				System.out.println("oi");
				dao.save(oi);
			}
		}
		
	}

}
